﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace Reborn_WorldServer.App1AppHandler
{
    public class PendingUserInputData
    {
        private string inputTitle = "";
        private string message = "";
        private List<string> choices = new List<string>();
        private string defaultChoice = "";

        public PendingUserInputData(string inputTitle, string message, List<string> choices, string defaultChoice)
        {
            this.inputTitle = inputTitle;
            this.message = message;
            this.choices = choices;
            this.defaultChoice = defaultChoice;
        }

        public string toXml(long id)
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("pendingUserInputData");
            xmldoc.WriteAttributeString("id", id.ToString());
            xmldoc.WriteAttributeString("inputTitle", inputTitle);
            xmldoc.WriteAttributeString("defaultChoice", defaultChoice);

            xmldoc.WriteStartElement("message");
            xmldoc.WriteString(message);
            xmldoc.WriteEndElement();

            xmldoc.WriteStartElement("choices");
            foreach (string choice in choices)
                xmldoc.WriteRaw("<choice>" + choice + "</choice>");
            xmldoc.WriteEndElement();

            xmldoc.WriteEndElement();

            xmldoc.Flush();
            xmldoc.Close();
            stringWriter.Flush();
            result = stringWriter.ToString();

            return result;
        }
    }
}
